package com.lap.context.starter.autoconfigure;

import com.lap.context.starter.autoconfigure.properties.HeaderProperties;
import com.lap.context.starter.core.interceptor.LangInterceptor;
import com.lap.context.starter.core.interceptor.RequestIdInterceptor;
import com.lap.context.starter.core.interceptor.UserInterceptor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Slf4j
@ConditionalOnWebApplication
@AutoConfiguration
@EnableConfigurationProperties(HeaderProperties.class)
public class WebAutoConfiguration implements WebMvcConfigurer {

  @Resource private LocaleChangeInterceptor localeChangeInterceptor;
  @Resource private LangInterceptor langInterceptor;
  @Resource private UserInterceptor userInterceptor;
  @Resource private RequestIdInterceptor requestIdInterceptor;

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(requestIdInterceptor);
    registry.addInterceptor(userInterceptor);
    registry.addInterceptor(localeChangeInterceptor);
    registry.addInterceptor(langInterceptor);
  }
}
